﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
using ZG_member.BLL;
using System.Configuration;

namespace ZG_member
{
    public partial class replystatistics : Form
    {
        public replystatistics()
        {

            InitializeComponent();
            skinEngine1.SkinFile = Application.StartupPath + ConfigurationManager.AppSettings["Skin"];
            this.Opacity = 0;
        }

        private void replystatistics_Load(object sender, EventArgs e)
        {
            MessageBox.Show("对不起，您未开通此功能");
            this.Close();
            
            this.timer1.Start();
            dtpStart.Value = dtpStart.Value.AddMonths(-1);
            //Series s2 = new Series("回信统计");
            //chart1.Series.Add(s2);
        }

        private void btnsubmit_Click(object sender, EventArgs e)
        {
            collection collBll = new collection();
            //string unit = "";
            DataTable dt;
            //string tiaojian = "";
            List<string> bili = new List<string>();
            List<string> name = new List<string>();
            dt = collBll.GetList("select COUNT(collectionsresult) as 数量,collectionsresult as 回信条件 from dbo.collection where collectionsresult in('a','b','c') and  memberid like '%" + this.textBox1.Text + "%' and time > '" + dtpStart.Value + "' and time < '" + dtpEnd.Value + "' group by collectionsresult").Tables[0];
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                bili.Add(dt.Rows[i]["数量"].ToString());
                name.Add(dt.Rows[i]["回信条件"].ToString() + " 数量为:" + dt.Rows[i]["数量"].ToString());

            }
            chart1.Series["Series1"]["PieLabelStyle"] = "Outside";
            chart1.Series["Series1"]["PieLinelColor"] = "Red";
            chart1.Series[0].Points.DataBindXY(name, bili);
            chart1.DataBind();
            dgvDate.DataSource = dt;
            //chart1.DataSource = null;
            ////select COUNT(collectionsresult) from dbo.collection where collectionsresult = 'A' and memberid like '%%' and time>'2013-5-5' and time<'2013-5-18'
            ////renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT)); 
            //chart1.DataSource = dt;
            ////Axis a = this.

            //chart1.Series["回信统计"].XValueMember = "回信条件";
            //chart1.Series["回信统计"].YValueMembers = "数量";
            //chart1.Series["回信统计"].IsValueShownAsLabel = true;
            //chart1.DataBind();

            //chart1.ChartAreas["ChartArea1"].AxisX.Title = "查询所有";
            //dgvDate.DataSource = dt;
            //if (dt.Rows.Count > 9) //当X轴超过9时就会显示不完全
            //{
            //    //设置X轴坐标的间隔为1
            //    chart1.ChartAreas["ChartArea1"].AxisX.Interval = 1;
            //    //设置X轴坐标的偏移为1
            //    chart1.ChartAreas["ChartArea1"].AxisX.IntervalOffset = 1;
            //    //设置交错显示，例如数据多时可分两行显示
            //    chart1.ChartAreas["ChartArea1"].AxisX.LabelStyle.IsStaggered = true;
            //}
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            this.Left += 2;
            this.Opacity += 0.1;
            if (Opacity == 1)
            {
                this.timer1.Stop();

            }
        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            this.Top = this.Top + 10;
            this.Opacity = this.Opacity - 0.06;
            if (Opacity <= 0)
            {
                this.timer2.Stop();
                this.Close();
            }
        }
        int flag = 0;

        private void replystatistics_FormClosing(object sender, FormClosingEventArgs e)
        {
            //if (flag == 0)
            //{
            //    e.Cancel = true;
            //    flag = 1;
            //    this.timer2.Start();
            //}
        }

        private void btnExport_Click(object sender, EventArgs e)
        {

        }

        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!(((e.KeyChar >= '0') && (e.KeyChar <= '9')) || e.KeyChar <= 31))
            {
                //if (e.KeyChar == '.')
                //{
                //    if (((TextBox)sender).Text.Trim().IndexOf('.') > -1)
                //        e.Handled = true;
                //}
                //else
                e.Handled = true;
            }
            else
            {
                if (e.KeyChar <= 31)
                {
                    e.Handled = false;
                }
                else if (((TextBox)sender).Text.Trim().IndexOf('.') > -1)
                {
                    if (((TextBox)sender).Text.Trim().Substring(((TextBox)sender).Text.Trim().IndexOf('.') + 1).Length >= 4)
                        e.Handled = true;
                }
            }
        }


    }
}
